import pointGoodsApi from '../../api/pointGoodsApi'
import pointApi from '../../api/pointApi'
Component({

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
      pageNum: 0,
      pageSize: 10,
      list: [],
      isMore: true,
      pointCount: 0
    },
    lifetimes: {
      attached: function() { 
        this.getList(1)
      },
      detached: function() {
        // 在组件实例被从页面节点树移除时执行
      },
    },

    pageLifetimes: {
      // 组件所在页面的生命周期函数
      show: async function () { 

        let res = await pointApi.get({
          openid: wx.getStorageSync('openid')
        })
        
        if(res){
          this.setData({
            pointCount: res.count
          })
        }
      },
      hide: function () { },
     
    },


   

    /**
     * 组件的方法列表
     */
    methods: {
      async getList(num){
        if(!this.data.isMore){
          return
        }
        this.data.pageNum = num
        let res = await pointGoodsApi.getList({
          pageNum: this.data.pageNum,
          pageSize: this.data.pageSize
        })
        this.setData({
          list: this.data.list.concat(res),
          isMore: res.length == this.data.pageSize
        })
      },

      async refresh(){
        this.setData({
          list: [],
          isMore: true
        })
        await this.getList(1)
      },
  
      toDetail(e){
        let item = e.currentTarget.dataset.item
        wx.navigateTo({
          url: '/pointShop/pointGoodsDetail/pointGoodsDetail?_id=' + item._id,
        })
      },

      toShop(){
        wx.navigateTo({
          url: '/pointShop/pointGoodsList/pointGoodsList',
        })
      },
      tipPoint(){
        wx.showModal({
          title: '提示',
          content: '积分可通过发布钓点和评论钓点获取',
          success (res) {
            
          }
        })
      }
    }
})